<?php
// +----------------------------------------------------------------------
// | 专利订单联系人管理
// +----------------------------------------------------------------------
// | Copyright (c) 2015
// +----------------------------------------------------------------------
// | Author: baiping 125618036@qq.com http://www.webipcode.com
// +----------------------------------------------------------------------
// |2016-1-14 下午5:59:13
// +----------------------------------------------------------------------
defined('BASEPATH') OR exit('No direct script access allowed');
class Patent_order_contacts_model extends CI_Model{
	
	private $db_table_name;
	public function __construct(){
		parent::__construct();
		$this->db_table_name = 'patent_order_contacts';
	}
	/**
	 * 执行wher条件
	 * @param unknown_type $where
	 * @author Baip
	 */
	private function _where($where){
		if ( is_array( $where ) ){
			foreach ( $where as $key => $val ){
				if ( is_array( $val ) ){
					$this->db->where_in($key, $val);
					unset($where[$key]);
				}else{
					$this->db->where($key, $val);
				}
			}
		}
		return true;
	}
	
	/**
	 * 添加数据
	 */
	public function addData($inser_id){
		return false;
		$data_arr = $this->postData();
		$data_arr['pid'] = $inser_id;
		$query = $this->db->insert($this->db_table_name, $data_arr);
		return $this->db->insert_id();
	}
	
	/**
	 * post接收值
	 */
	private function postData(){
		$real_name = $this->input->post('real_name',true);//称呼
		$mobile    = $this->input->post('mobile',true);//手机号
		$email     = $this->input->post('email',true);//邮箱
		$qq        = $this->input->post('qq',true);//qq
		$weixin    = $this->input->post('weixin',true);//微信号
	
		//产生随机字符串
		$data_arr['real_name'] = $real_name;
		$data_arr['mobile'] = $mobile;
		$data_arr['email'] = $email;
		$data_arr['qq'] = $qq;
		$data_arr['weixin'] = $weixin;
		return $data_arr;
	}
	
	/**
	 * 获取一条数据
	 * @param array $where
	 * @param string $field
	 * @param int $limit
	 * @param string $order
	 */
	public function getFind($where, $field="*", $limit=1, $order="pid DESC"){
		$this->_where($where);
		$this->db->from($this->db_table_name);
		$this->db->select($field);
		$this->db->limit($limit);
		$this->db->order_by($order);
		$res = $this->db->get();
		return $res->row();
	}
}